package com.beasts.antpage.sh.service;

import com.beasts.antpage.sh.entity.APCommonOperation;
import com.beasts.antpage.sh.entity.RemindMessage;
import com.beasts.antpage.sh.repository.CommonOperationRepository;
import com.beasts.antpage.sh.repository.MessageRepository;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author Locker
 * @date 20/04/2018 11:02 AM
 * @since 1.0
 */
@Service
public class CommonOperationServiceImpl implements ICommonOperationService {

    @Autowired
    private CommonOperationRepository commonOperationRepository;


    @Override
    public List<APCommonOperation> findAll(String name) {
        return null;
    }

    @Override
    public String saveOperation(HttpServletRequest req) {
        String appId = req.getParameter("appId");
        String userId = req.getParameter("userId");
        String url = req.getParameter("url");
        String title = req.getParameter("title");
        String id = req.getParameter("id");
        String pageId = req.getParameter("pageId");
        String pageTitle = req.getParameter("pageTitle");
        try {
            APCommonOperation commonOperation = new APCommonOperation();
            commonOperation.setAppId(appId);
            commonOperation.setUserId(userId);
            commonOperation.setUrl(url);
            commonOperation.setTitle(title);
            commonOperation.setId(id);
            commonOperation.setPageId(pageId);
            commonOperation.setPageTitle(pageTitle);
            commonOperationRepository.save((commonOperation));
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
        return null;

    }

    @Override
    public List<APCommonOperation> findByUserId(HttpServletRequest req) {
        String appId = req.getParameter("appId");
        String pageId = req.getParameter("pageId");
        String userId = req.getParameter("userId");
        return commonOperationRepository.findByAppIdAndPageIdAndUserId(appId,pageId,userId);
    }
}
